#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 
# Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
# 

"""
File: run18.py
Author: zhangyang(zhangyang40@baidu.com)
Date: 2018/1/5 0005 15:05
"""

import Queue


class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    # 返回从上到下每个节点值列表，例：[1,2,3]
    def PrintFromTopToBottom(self, root):
        list = []
        if not root:
            return []
        queue = Queue.Queue()
        queue.put(root)
        while queue.empty():
            node = queue.get()
            list.append(node.val)
            if node.left:
                queue.put(node.left)
            if node.right:
                queue.put(node.right)
        return list
